//
//  UserLandViewController.m
//  UI-豆瓣项目APP
//
//  Created by dllo on 15/10/31.
//  Copyright © 2015年 孙鹏. All rights reserved.
//

#import "UserLandViewController.h"
#import "UserLandView.h"
#import "UserLoginViewController.h"
#import "DateBaseSingleton.h"
@interface UserLandViewController ()<UserLandViewDelegete>
@property (nonatomic,retain)UserLandView *userLandV;
@end

@implementation UserLandViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationItem.title = @"用户登陆";
    self.view.backgroundColor = [UIColor whiteColor];
    self.userLandV = [[UserLandView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    [self.view addSubview:self.userLandV];
    [self.userLandV release];
    
    
    self.userLandV.delegete = self;
    
    
    // Do any additional setup after loading the view.
}




- (void)presentToLoginView
{
   
        
        UserLoginViewController *userLoginVC = [[UserLoginViewController alloc]init];
        [self.navigationController pushViewController:userLoginVC animated:YES];
        
    
    
   
    
    
    
    
}

-(void)presentToLandView{
    
 
    NSMutableArray *array = [NSMutableArray array];
    
    array = [[DateBaseSingleton shareDateBase]selectUser];
 
    for (UserList *user in array) {
        if ([user.userName isEqualToString:self.userLandV.userName1.text])
        {
            self.user = [[UserList alloc]init];
            self.user = user;
            
        }
        
      
        
        
//
        
        
    }
    

    
    if ([self.userLandV.userName1.text isEqualToString:self.user.userName] &&[self.userLandV.code1.text isEqualToString:self.user.code]) {
        
        [[NSUserDefaults standardUserDefaults]setObject:self.user.userName forKey:@"userName"];
        NSLog(@"%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"userName"]);
        
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"登陆成功" preferredStyle:UIAlertControllerStyleAlert];
        
        [self presentViewController:alertC animated:YES completion:^{
            
            
        }];
        
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
        }];
        [alertC addAction:action];
        
        
        [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"isLogin"];
        //
    }
    else
    {
        
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"请输入正确的用户名和密码" preferredStyle:UIAlertControllerStyleAlert];
        
        [self presentViewController:alertC animated:YES completion:^{
            
            
        }];
        
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
        }];
        [alertC addAction:action];
    
    
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
